<template>
  <div>
    <div class="search-box">
      <el-form :model="searchForm" label-width="80px" inline size="small">
        <el-form-item label="标签名称">
          <el-input v-model="searchForm.name" placeholder="请输入标签名称" />
        </el-form-item>
        <el-form-item label="启用状态">
          <el-select v-model="searchForm.status" placeholder="请选择标签状态">
            <el-option label="启用" value="1" />
            <el-option label="禁用" value="0" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-refresh" @click="reset">重置</el-button>
          <el-button icon="el-icon-search" type="primary" @click="search"
            >查询</el-button
          >
        </el-form-item>
      </el-form>
      <div>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-plus"
          @click="addCustomTag"
          >新增客户标签</el-button
        >
      </div>
      <div style="margin-top: 10px">
        <el-table
          :data="tableData.data"
          border
          style="width: 100%"
          size="small"
        >
          <el-table-column prop="name" label="标签名称" align="center" />
          <el-table-column prop="status" label="启用状态" align="center">
            <!--            <template slot-scope="scope">-->
            <!--              <el-tag-->
            <!--                :type="scope.row.status === 1 ? 'success' : 'danger'"-->
            <!--                disable-transitions-->
            <!--                >{{ scope.row.status === 1 ? "启用" : "禁用" }}</el-tag-->
            <!--              >-->
            <!--            </template>-->
          </el-table-column>
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="handleEdit(scope.row)"
                >编辑</el-button
              >
              <el-button
                type="text"
                size="small"
                @click="handleDelete(scope.row)"
                >删除</el-button
              >
              <!--              <el-switch v-model="scope.row.status"></el-switch>-->
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="pageRight">
        <el-pagination
          :current-page="searchForm.pageNum"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="searchForm.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <el-dialog
      title="新建客户标签"
      :before-close="handleClose"
      :visible.sync="dialogVisible"
      width="600px"
    >
      <el-form
        :rules="rules"
        ref="detailForm"
        :model="detailForm"
        label-width="80px"
        size="small"
      >
        <el-form-item label="标签名称" prop="name">
          <el-input v-model="detailForm.name" placeholder="请输入标签名称" />
        </el-form-item>
        <el-form-item label="启用状态" prop="status">
          <el-radio-group v-model="detailForm.status">
            <el-radio :label="1">启用</el-radio>
            <el-radio :label="0">禁用</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item> </el-form-item>
      </el-form>
      <div style="text-align: center">
        <el-button
          size="small"
          style="width: 100px"
          @click="onsubmit('detailForm')"
          type="primary"
          >保存</el-button
        >

        <el-button size="small" style="width: 100px" @click="handleClose"
          >取消</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  name: "customTag",
  data() {
    return {
      searchForm: {
        name: "",
        status: "",
        pageNum: 1,
        pageSize: 10
      },
      tableData: {
        data: [],
        total: 0
      },
      dialogVisible: false,
      detailForm: {
        name: "",
        status: 1
      },
      rules: {
        name: [
          {
            required: true,
            message: "请输入标签名称",
            trigger: "blur"
          }
        ],
        status: [
          {
            required: true,
            message: "请选择启用状态",
            trigger: "blur"
          }
        ]
      }
    };
  },
  methods: {
    onsubmit(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          console.log(this.detailForm);
          this.dialogVisible = false;
          setTimeout(() => {
            this.$refs.detailForm.resetFields();
          }, 500);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    handleClose() {
      this.dialogVisible = false;
      setTimeout(() => {
        this.$refs.detailForm.resetFields();
      }, 500);
    },
    handleSizeChange(val) {
      this.searchForm.pageSize = val;
    },
    handleCurrentChange(val) {
      this.searchForm.pageNum = val;
    },
    addCustomTag() {
      this.dialogVisible = true;
    },
    search() {},
    reset() {
      this.searchForm = {
        name: "",
        status: "",
        pageNum: 1,
        pageSize: 10
      };
    }
  }
};
</script>

<style scoped lang="scss"></style>
